package com.yinxin.Util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author: YinXin
 * @Date: 2021/10/2 19:28
 * @Version: 1.0
 * @description:
 */
public class ProxyController {
    @Value("${proxy.address}")
    private String proxyAddress;

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping("/api/**")
    @ResponseBody
    public Object proxy(HttpServletRequest request){
        System.out.println(proxyAddress);
        return restTemplate.getForObject(
                proxyAddress+request.getRequestURI().replace("/api",""),
                Object.class);
    }
}
